import api from '../../api';
import { message } from 'antd';
import { forEach } from 'lodash';

export default {
  namespace: 'creditOccupationM',
  state: {},
  effects: {
    //查询授信占用
    *getMonitor({ payload, callback }, { call, put, select }) {
      const res = yield call(api.creditOccupation.getMonitor, payload);
      if (res) {
        if (res.code == 0) {
          callback(res.data);
        } else {
          message.error(res.msg || '查询授信占用失败');
        }
      } else {
        message.error('查询授信占用失败');
      }
    },

    //查询授信占用
    *getMonitorDetail({ payload, callback }, { call, put, select }) {
      const res = yield call(api.creditOccupation.getMonitorDetail, payload);
      if (res) {
        if (res.code == 0) {
          callback(res.data);
        } else {
          message.error(res.msg || '查询授信占用情况明细失败');
        }
      } else {
        message.error('查询授信占用情况明细失败');
      }
    },

    //查询最近交易日
    *getRecentDay({ payload, callback }, { call, put, select }) {
      const res = yield call(api.creditOccupation.getRecentDay, payload);
      if (res) {
        if (res.code == 0) {
          callback(res.data);
        } else {
          message.error(res.msg || '查询最近交易日失败');
        }
      } else {
        message.error('查询最近交易日失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
